package com.itheima.io.字符流;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
/**
 *
 */
public class CharDtreamDemo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "it黑马";
        //使用平台默认字符集将字符串编码为字节
        byte[] bytes = s.getBytes();
        System.out.println(Arrays.toString(bytes));
        //使用指定字符集将string编码为字节
        byte[] gbks = s.getBytes("GBK");
        System.out.println(Arrays.toString(gbks));

        //使用平台默认编码集解码
        String s1 = new String(bytes);
        System.out.println("s1 = " + s1);
        String s2 = new String(gbks);
        System.out.println("s2 = " + s2);

        //使用指定编码集解码
        System.out.println(new String(bytes, "GBK"));
        System.out.println(new String(gbks, "GBK"));
    }
}
